﻿using System;
using System.Windows.Forms;
using Microsoft.Win32;

namespace harbar.net.Utils.APM
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            app = new App();
            app.Run(args);
        }

        public static App app;

        internal class App : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
        {
            public App()
            {
                this.IsSingleInstance = true;
                this.EnableVisualStyles = true;
                this.ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
            }

            protected override void OnCreateMainForm()
            {
                this.MainForm = new frmMain();
            }

            public Form AppForm
            {
                get { return base.MainForm; }
            }

            protected override bool OnStartup(Microsoft.VisualBasic.ApplicationServices.StartupEventArgs eventArgs)
            {
                return base.OnStartup(eventArgs);
            }

            protected override void OnStartupNextInstance(Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs eventArgs)
            {
                base.OnStartupNextInstance(eventArgs);
                if (this.MainForm != null)
                {
                    this.MainForm.Show();
                    this.MainForm.WindowState = FormWindowState.Normal;
                    this.MainForm.Activate();
                    this.MainForm.Focus();
                }
            }

        }

    }
}
